home *** CD-ROM | disk | FTP | other *** search
- Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
- From: grantp@usa.pipeline.com(Pete Grant)
- Newsgroups: comp.lang.c++
- Subject: Re: Q: throwing exceptions in constructors
- Date: 25 Mar 1996 11:52:00 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4j61d0$but@news1.h1.usa.pipeline.com>
- References: <opu3ze7xf4.fsf@sweetbay.will.uiuc.edu>
- NNTP-Posting-Host: 38.8.120.13
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete Grant)
- X-Newsreader: Pipeline v3.5.0
-
- On Mar 24, 1996 19:51:11 in article <Q: throwing exceptions in
- constructors>, 'Dragos-Anton Manolescu <manolesc@uiuc.edu>' wrote:
-
-
- >I was wondering if it's possible to throw an exception from within a
- >constructor (a word of caution: this is my first attempt to use
- >exceptions :-) Suppose the constructor calls new and this fails. Then
- >I would like to throw an exception to inform the calling program that
- >an abnormal situation occured. Is this possible? I tried something
- >like:
- >
- >...
- >MyClass myObject(1,2,3)
- >...
- >
- >inside a try statement but the compiler complained (I use g++ 2.7.2,
- >BTW). Am I doing something wrong? What would be an elegant way to
- >handle this?
- >
- Yes, it's possible. Post a sample of your code and the wording
- the compiler's error message, so we can point out how you may
- correct your problem.
-
- BTW, Scott Meyers in his book "More Effective C++" devotes an
- entire chapter to dealing with exceptions within constructors
- and destructors. IMO, this book is required reading as soon
- as one has progressed beyond the newby status. The surprising
- part about this book is that is contains some eye openers for
- the experts as well as those in the intermediate/beginner
- categories.
-
- This book was written in November 95 and is about as current
- as you can get. Mr. Meyers talks about most of the recent
- additions/changes to the language as well as pointing out
- the proposed changes which could affect the way you code
- today in preparation for tomorrow.
-
- Pardon the sales pitch. I'm not connected with Scott Meyers
- in any way, I just think that it's an excellent book.
-
- --
- Pete Grant
- Kalevi, Inc.
- Software Engineering & development
-